From 64bc85a3506fd7390193a7775fdae6424e45f481 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 13 Mar 2005 07:18:13 +0000 Subject: [PATCH] Check and fix for pages whose page_latest is not set to the latest revision --- maintenance/orphans.php | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/maintenance/orphans.php b/maintenance/orphans.php index 7532344c98..fa5877373a 100755 --- a/maintenance/orphans.php +++ b/maintenance/orphans.php @@ -35,6 +35,7 @@ require_once( 'commandLine.inc' ); $wgTitle = Title::newFromText( 'Orphan revision cleanup script' ); checkOrphans( isset( $options['fix'] ) ); +checkSeparation( isset( $options['fix'] ) ); #checkWidows( isset( $options['fix'] ) ); # ------ @@ -132,4 +133,75 @@ function checkWidows( $fix ) { } } + +function checkSeparation( $fix ) { + $dbw =& wfGetDB( DB_MASTER ); + $page = $dbw->tableName( 'page' ); + $revision = $dbw->tableName( 'revision' ); + $text = $dbw->tableName( 'text' ); + + if( $fix ) { + $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE, $text WRITE" ); + } + + echo "\nChecking for pages whose page_latest links are incorrect... (this may take a while on a large wiki)\n"; + $result = $dbw->query( " + SELECT * + FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id + "); + $found = 0; + while( $row = $dbw->fetchObject( $result ) ) { + $result2 = $dbw->query( " + SELECT MAX(rev_timestamp) as max_timestamp + FROM $revision + WHERE rev_page=$row->page_id + " ); + $row2 = $dbw->fetchObject( $result2 ); + $dbw->freeResult( $result2 ); + if( $row2 ) { + if( $row->rev_timestamp != $row2->max_timestamp ) { + if( $found == 0 ) { + printf( "%10s %10s %14s %14s\n", + 'page_id', 'rev_id', 'timestamp', 'max timestamp' ); + } + ++$found; + printf( "%10d %10d %14s %14s\n", + $row->page_id, + $row->page_latest, + $row->rev_timestamp, + $row2->max_timestamp ); + if( $fix ) { + # ... + $maxId = $dbw->selectField( + 'revision', + 'rev_id', + array( + 'rev_page' => $row->page_id, + 'rev_timestamp' => $row2->max_timestamp ) ); + echo "... updating to revision $maxId\n"; + $maxRev = Revision::newFromId( $maxId ); + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); + $article = new Article( $title ); + $article->updateRevisionOn( $dbw, $maxId, $maxRev->getText() ); + } + } + } else { + echo "wtf\n"; + } + } + + if( $found ) { + echo "Found $found pages with incorrect latest revision.\n"; + } else { + echo "No pages with incorrect latest revision. Yay!\n"; + } + if( !$fix && $found > 0 ) { + echo "Run again with --fix to remove these entries automatically.\n"; + } + + if( $fix ) { + $dbw->query( "UNLOCK TABLES" ); + } +} + ?> \ No newline at end of file -- 2.20.1